home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / lib / partman / init.d / 30parted < prev    next >
Text File  |  2009-10-28  |  6KB  |  236 lines

  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. . /lib/partman/lib/base.sh
  6. . /usr/share/debconf/confmodule
  7.  
  8. ORIG_IFS="$IFS"
  9.  
  10. is_inactive_md() {
  11.     local number
  12.     number=$(echo "$1" | sed -n -e 's,/dev/md/\?,,p')
  13.     if [ "$number" ] && ! grep -q "^md$number : active" /proc/mdstat; then
  14.         return 0
  15.     fi
  16.     return 1
  17. }
  18.  
  19. part_of_sataraid () {
  20.     local raiddev
  21.     for raiddev in $(dmraid -r -c); do
  22.         if [ "$(readlink -f $raiddev)" = $1 ]; then
  23.             return 0
  24.         fi
  25.     done
  26.     return 1
  27. }
  28.  
  29. part_of_multipath() {
  30.     local mpdev
  31.     type multipath >/dev/null 2>&1 || return 1
  32.  
  33.     if is_multipath_part $1; then
  34.         return 0
  35.     fi
  36.     # The block devices that make up the multipath:
  37.     # Output looks like \_ 4:0:0:1 sdc 8:32 ...
  38.     for mpdev in $(multipath -l | \
  39.                grep '_ \([#0-9]\+:\)\{3\}[#0-9]\+ [hs]d[a-z]\+ [0-9]\+:[0-9]\+' | \
  40.                cut -f4 -d' '); do
  41.         if [ "$(readlink -f /dev/$mpdev)" = $1 ]; then
  42.             return 0
  43.         fi
  44.     done
  45.     return 1
  46. }
  47.  
  48. if [ ! -f /var/run/parted_server.pid ]; then
  49.     mkdir -p /var/run
  50.     parted_server
  51.     RET=$?
  52.     if [ $RET != 0 ]; then
  53.         # TODO: How do we signal we couldn't start parted_server properly?
  54.         exit $RET
  55.     fi
  56.  
  57.     rm -rf /var/lib/partman/old_devices
  58.     if [ -d $DEVICES ]; then
  59.         mv $DEVICES /var/lib/partman/old_devices
  60.     fi
  61.     mkdir $DEVICES || true
  62.  
  63.     IFS="$NL"
  64.     for partdev in $(parted_devices |
  65.         sed 's,^/dev/\(ide\|scsi\|[hs]d\|md/\?[0-9]\+\),!/dev/\1,' |
  66.         sort |
  67.         sed 's,^!,,' ); do
  68.  
  69.         IFS="$TAB"
  70.         set -- $partdev
  71.         IFS="$ORIG_IFS"
  72.  
  73.         device=$1
  74.         size=$2
  75.         model=$3
  76.  
  77.         # Skip mtd devices since they aren't supported by parted
  78.         if echo $device | grep -q '/dev/mtd'; then
  79.             continue
  80.         fi
  81.  
  82.         # Skip MD devices which are not active
  83.         if [ -e /proc/mdstat ]; then
  84.             if is_inactive_md $device; then
  85.                 continue
  86.             fi
  87.         fi
  88.  
  89.         # Skip devices that are part of a dmraid device
  90.         if type dmraid >/dev/null 2>&1 && \
  91.            dmraid -r -c >/dev/null 2>&1; then
  92.             if part_of_sataraid $device && \
  93.                [ -f /var/lib/disk-detect/activate_dmraid ]; then
  94.                 continue
  95.             fi
  96.         fi
  97.  
  98.         # Skip devices that are part of a multipathed device
  99.         if part_of_multipath $device; then
  100.             continue
  101.         fi
  102.  
  103.         dirname=$(echo $device | sed 's:/:=:g')
  104.         dev=$DEVICES/$dirname
  105.         if [ -d /var/lib/partman/old_devices/$dirname ]; then
  106.             mv /var/lib/partman/old_devices/$dirname $dev
  107.         else
  108.             mkdir $dev || continue
  109.         fi
  110.         printf "%s" "$device" >$dev/device
  111.         printf "%s" "$size" >$dev/size
  112.         printf "%s" "$model" >$dev/model
  113.  
  114.         # Set the sataraid flag for dmraid arrays.
  115.         if type dmraid >/dev/null 2>&1 && \
  116.            dmraid -s -c >/dev/null 2>&1; then
  117.             if dmraid -sa -c | grep -q $(basename $device); then
  118.                 >$dev/sataraid
  119.             fi
  120.         fi
  121.  
  122.         cd $dev
  123.         open_dialog OPEN "$(cat $dev/device)"
  124.         read_line response
  125.         close_dialog
  126.         if [ "$response" = failed ]; then
  127.             cd /
  128.             rm -rf $dev
  129.         fi
  130.     done
  131.  
  132.     db_get partman/filter_mounted
  133.     if [ "$RET" = true ]; then
  134.         # Get a list of active mounts in a more convenient format.
  135.         mounts=
  136.         while read dev mp rest; do
  137.             [ -e "$dev" ] || continue
  138.             mappeddev="$(mapdevfs "$dev")" || true
  139.             if [ "$mappeddev" ]; then
  140.                 dev="$mappeddev"
  141.             fi
  142.             mounts="${mounts:+$mounts$NL}$dev $mp"
  143.         done < /proc/mounts
  144.         # For each disk, check for any active mounts on it. If the
  145.         # only thing mounted is the installation medium and it uses
  146.         # more or less the whole disk, then silently exclude that
  147.         # disk; if the installation medium is mounted but doesn't
  148.         # use the whole disk, issue a warning that partitioning may
  149.         # be difficult; if anything else is mounted, offer to
  150.         # unmount it.
  151.         disks_unmount=
  152.         parts_unmount=
  153.         part_warn=
  154.         for dev in $DEVICES/*; do
  155.             [ -d "$dev" ] || continue
  156.             cd $dev
  157.             free=0
  158.             parts=
  159.             instparts=
  160.             seen_unmounted=
  161.             open_dialog PARTITIONS
  162.             while { read_line num id size type fs path name; [ "$id" ]; }; do
  163.                 if [ "$fs" = free ]; then
  164.                     free="$(($free + $size))"
  165.                     continue
  166.                 fi
  167.                 mappedpath="$(mapdevfs "$path")" || true
  168.                 if [ "$mappedpath" ]; then
  169.                     path="$mappedpath"
  170.                 fi
  171.                 mp=
  172.                 IFS="$NL"
  173.                 for line in $mounts; do
  174.                     restore_ifs
  175.                     if [ "$path" = "${line%% *}" ]; then
  176.                         mp="${line#* }"
  177.                         break
  178.                     fi
  179.                     IFS="$NL"
  180.                 done
  181.                 restore_ifs
  182.                 if [ "$mp" = /cdrom ]; then
  183.                     instparts="${instparts:+$instparts }$path"
  184.                 elif [ "$mp" ]; then
  185.                     parts="${parts:+$parts }$path"
  186.                 else
  187.                     seen_unmounted=1
  188.                 fi
  189.             done
  190.             close_dialog
  191.             if [ "$instparts" ]; then
  192.                 if [ -z "$seen_unmounted" ] && \
  193.                    longint_le "$free" 16777216; then
  194.                     # The installation medium uses more
  195.                     # or less the whole disk.
  196.                     open_dialog CLOSE
  197.                     close_dialog
  198.                     cd /
  199.                     rm -rf "$dev"
  200.                 else
  201.                     # There's an installation medium
  202.                     # here, but it doesn't use the whole
  203.                     # disk.
  204.                     part_warn="$instparts"
  205.                     >installation_medium
  206.                 fi
  207.             elif [ "$parts" ]; then
  208.                 # Something other than an installation
  209.                 # medium is mounted.
  210.                 disks_unmount="${disks_unmount:+$disks_unmount }$(cat device)"
  211.                 parts_unmount="${parts_unmount:+$parts_unmount }$parts"
  212.             fi
  213.         done
  214.         if [ "$disks_unmount" ]; then
  215.             db_subst partman/unmount_active DISKS "$(echo "$disks_unmount" | sed 's/ /, /g')"
  216.             db_fset partman/unmount_active seen false
  217.             db_input critical partman/unmount_active || true
  218.             db_go || exit 10
  219.             db_get partman/unmount_active || RET=
  220.             if [ "$RET" = true ]; then
  221.                 umount $parts_unmount || true
  222.             fi
  223.         fi
  224.         if [ "$part_warn" ]; then
  225.             db_subst partman/installation_medium_mounted PARTITION "$part_warn"
  226.             db_fset partman/installation_medium_mounted seen false
  227.             db_capb align
  228.             db_input high partman/installation_medium_mounted || true
  229.             db_go || true
  230.             db_capb backup align
  231.         fi
  232.     fi
  233.  
  234.     rm -rf /var/lib/partman/old_devices
  235. fi
  236.